#include <iostream>
#include <vector>

using namespace std;

// 2566. 替换一个数字后的最大差值
// https://leetcode.cn/problems/maximum-difference-by-remapping-a-digit/description/?envType=daily-question&envId=2025-06-14

class Solution
{
public:
    int minMaxDifference(int num)
    {
        string s = to_string(num);
        string temp = s;
        char reMapChar = 'A';
        for (auto &ch : s)
        {
            if (ch != '9' && reMapChar == 'A')
            {
                reMapChar = ch;
            }
            if (reMapChar != 'A' && ch == reMapChar)
            {
                ch = '9';
            }
        }
        int maxNum = atoi(s.c_str());
        reMapChar = temp[0];
        for (auto &ch : temp)
        {
            if (ch == reMapChar)
            {
                ch = '0';
            }
        }
        int minNum = atoi(temp.c_str());
        return maxNum - minNum;
    }
};

int main()
{
    Solution solution{};
    solution.minMaxDifference(11891);
    return 0;
}